package com.orangelife.mobile.housepurchasing.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.curry.android.adapter.FatherAdapter;
import com.curry.orangelife.mobile.R;

import java.util.List;
import java.util.Map;

/**
 * Created by HeYuCan on 2016/5/25.
 */
public class SelectCityAdapter <T> extends FatherAdapter<T> {

    private Context mContext;
    private LayoutInflater listContainer;
    private List<Map<String,Object>> mList = null;
    private String currentType = "";

    class ViewHolder {
        public TextView tv_item_name;
        public TextView tv_address;
    }


    public SelectCityAdapter(Context context,
                                   List<Map<String,Object>> list) {
        this.mContext = context;
        listContainer = LayoutInflater.from(mContext);
        this.mList = list;
    }

    public void setCurrentType(String currentType) {
        this.currentType = currentType;
    }

    @Override
    public int getCount() {
        if (mList == null) {
            return 0;
        }
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = listContainer.inflate(
                    R.layout.item_lv_select_cityorcomm, null);
            holder.tv_item_name = (TextView) convertView
                    .findViewById(R.id.tv_community_name);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
      String cityName=(String) mList.get(position).get("city");
        holder.tv_item_name.setText(cityName);
        return convertView;
    }


    @Override
    public BaseAdapter setList(List<T> list) {
        this.mList = (List<Map<String, Object>>) list;
        return SelectCityAdapter.this;
    }
    }


